import 'package:flutter/material.dart';
import 'package:xws/helpers/safe_state.dart';
import 'package:xws/utils/tools_util.dart';

/// 积分变动toast
class PointCh extends StatefulWidget {
  const PointCh({Key? key, required this.content}) : super(key: key);

  final String content;

  @override
  State<PointCh> createState() => _PointChState();
}

class _PointChState extends State<PointCh> with SafeState<PointCh> {
  double _bottom = 60;

  @override
  void initState() {
    super.initState();
    delayed(const Duration(milliseconds: 1)).then((_) {
      safeSetState(() => _bottom = 80);
      delayed(const Duration(milliseconds: 800)).then((_) {
        safeSetState(() => _bottom = 100);
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedContainer(
      duration: const Duration(milliseconds: 500),
      curve: Curves.ease,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          const Icon(Icons.toll_rounded, color: Colors.white, size: 20),
          const SizedBox(width: 6),
          Text(
            widget.content,
            style: const TextStyle(
              fontSize: 13,
              color: Colors.white,
            ),
          ),
        ],
      ),
      padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
      margin: EdgeInsets.only(bottom: _bottom),
      decoration: BoxDecoration(
        color: Colors.black.withOpacity(0.8),
        borderRadius: BorderRadius.circular(6),
      ),
    );
  }
}
